home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Tools / Win95 Secrets / SETUP.Z / W32SVFLT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-19  |  5.9 KB  |  211 lines

  1. //==================================
  2. // W32SVSPY - Matt Pietrek 1995
  3. // FILE: W32SVFLT.C
  4. //==================================
  5. #include <windows.h>
  6. #include <stdio.h>
  7. #include <string.h>
  8. #pragma hdrstop
  9. #include "w32srvdb.h"
  10. #include "w32svspy.h"
  11. #include "w32svflt.h"
  12.  
  13. void UpdateFilterDialogServiceList( HWND hWndDlg, unsigned index );
  14. void HandleWin32ServiceListboxDblClk( HWND hWndDlg );
  15.  
  16. void Handle_FilterDlg_WM_COMMAND(HWND hWndDlg, WPARAM wParam, LPARAM lParam)
  17. {
  18.     switch ( LOWORD(wParam) )
  19.     {
  20.         case IDOK:
  21.  
  22.             // Fall through to IDCANCEL
  23.         case IDCANCEL:
  24.             EndDialog(hWndDlg, 0); return;
  25.             
  26.         case IDC_FILTER_LB_PROVIDERS:
  27.             if ( HIWORD(wParam) == LBN_SELCHANGE )
  28.             {
  29.                 DWORD currSel = SendMessage((HWND)lParam, LB_GETCURSEL, 0, 0);
  30.                 if ( currSel != LB_ERR )
  31.                     UpdateFilterDialogServiceList( hWndDlg, currSel );
  32.             }
  33.             break;
  34.             
  35.         case IDC_FILTER_LB_SERVICES:
  36.             if ( HIWORD(wParam) == LBN_DBLCLK )
  37.                 HandleWin32ServiceListboxDblClk( hWndDlg );
  38.             break;
  39.     }
  40. }
  41.  
  42. void Handle_FilterDlg_WM_INITDIALOG(HWND hWndDlg, WPARAM wParam, LPARAM lParam)
  43. {
  44.     unsigned i;
  45.     HWND hWndLb;
  46.     
  47.     hWndLb = GetDlgItem(hWndDlg,IDC_FILTER_LB_PROVIDERS);
  48.     
  49.     for ( i=0; i < CWin32ServiceVxDs; i++ )
  50.     {
  51.         SendMessage( hWndLb,
  52.                     LB_ADDSTRING,
  53.                     (WPARAM)0,
  54.                     (LPARAM)W32ServiceTable[i].pszVxDName );
  55.     }
  56.  
  57.     // Force the first VXD's services to be shown in the service list
  58.     SendMessage( hWndLb, LB_SETCURSEL, 0, 0 );
  59.     PostMessage( hWndDlg,
  60.                 WM_COMMAND,
  61.                 MAKEWPARAM(IDC_FILTER_LB_PROVIDERS, LBN_SELCHANGE),
  62.                 (LPARAM)hWndLb );
  63. }
  64.  
  65. void UpdateFilterDialogServiceList( HWND hWndDlg, unsigned index )
  66. {
  67.     unsigned i;
  68.     HWND hWndLb;
  69.     
  70.     hWndLb = GetDlgItem( hWndDlg, IDC_FILTER_LB_SERVICES );
  71.     
  72.     SendMessage( hWndLb, LB_RESETCONTENT, 0, 0 );
  73.     SendMessage( hWndLb, WM_SETREDRAW, FALSE, 0 );
  74.  
  75.     for ( i=0; i < W32ServiceTable[index].cServiceCalls; i++ )
  76.     {
  77.         char szBuffer[512];
  78.         
  79.         wsprintf(szBuffer, "%c %08X %s",
  80.                     W32ServiceTable[index].pServiceCalls[i].fIgnore ? '-': '+',
  81.                     W32ServiceTable[index].vxdID + i,
  82.                     W32ServiceTable[index].pServiceCalls[i].pszServiceName);
  83.  
  84.         SendMessage(hWndLb, LB_ADDSTRING, 0, (LPARAM)szBuffer );
  85.     }
  86.         
  87.     SendMessage( hWndLb, WM_SETREDRAW, TRUE, 0 );
  88. }
  89.  
  90. void HandleWin32ServiceListboxDblClk( HWND hWndDlg )
  91. {
  92.     DWORD currVxD;
  93.     DWORD currServ;
  94.     char szBuffer[512];
  95.     
  96.     currVxD = SendDlgItemMessage(hWndDlg, IDC_FILTER_LB_PROVIDERS,
  97.                                     LB_GETCURSEL, 0, 0);
  98.                             
  99.     if ( currVxD == LB_ERR )
  100.         return;
  101.  
  102.     currServ = SendDlgItemMessage( hWndDlg, IDC_FILTER_LB_SERVICES,
  103.                                     LB_GETCURSEL, 0, 0 );
  104.                         
  105.     if ( currServ == LB_ERR )
  106.         return;
  107.  
  108.     // Toggle the state of the fIgnore flag
  109.     W32ServiceTable[currVxD].pServiceCalls[currServ].fIgnore ^= 1;
  110.  
  111.     SendDlgItemMessage( hWndDlg, IDC_FILTER_LB_SERVICES, LB_GETTEXT, 
  112.                         currServ, (LPARAM)szBuffer );
  113.                     
  114.     szBuffer[0] = (szBuffer[0] == '+') ? '-' : '+';
  115.  
  116.     SendDlgItemMessage( hWndDlg, IDC_FILTER_LB_SERVICES, LB_DELETESTRING, 
  117.                         (WPARAM)currServ, 0 );
  118.     SendDlgItemMessage( hWndDlg, IDC_FILTER_LB_SERVICES, LB_INSERTSTRING, 
  119.                         (WPARAM)currServ, (LPARAM)szBuffer );
  120.     
  121.  
  122. BOOL CALLBACK W32SpyFilterDlgProc(HWND hWndDlg, UINT msg,
  123.                                     WPARAM wParam, LPARAM lParam)
  124. {
  125.     switch ( msg )
  126.     {
  127.         case WM_COMMAND:
  128.             Handle_FilterDlg_WM_COMMAND( hWndDlg, wParam, lParam );
  129.             break;
  130.  
  131.         case WM_INITDIALOG:
  132.             Handle_FilterDlg_WM_INITDIALOG( hWndDlg, wParam, lParam );
  133.             break;
  134.  
  135.         case WM_CLOSE:
  136.             EndDialog(hWndDlg, 0); return FALSE;
  137.     }
  138.     return FALSE;
  139. }
  140.  
  141. static void GetSavedFiltersFilename( PSTR pszBuffer )
  142. {
  143.     PSTR p;
  144.     
  145.     GetModuleFileName( 0, pszBuffer, MAX_PATH );
  146.     
  147.     p = strrchr( pszBuffer, '\\' );
  148.     strcpy( p+1, "w32svspy.flt" );
  149. }
  150.  
  151. BOOL SaveFilterValues(void)
  152. {
  153.     FILE * pFile;
  154.     char szSaveFileName[MAX_PATH];
  155.     unsigned i, j;
  156.     
  157.     GetSavedFiltersFilename( szSaveFileName );
  158.     pFile = fopen( szSaveFileName, "wb" );
  159.     if ( !pFile )
  160.     {
  161.         MessageBox(0, "Unable to open saved filters file!", 0, MB_OK);
  162.         return FALSE;
  163.     }
  164.     
  165.     for ( i=0; i < CWin32ServiceVxDs; i++ )
  166.     {
  167.         for ( j=0; j < W32ServiceTable[i].cServiceCalls; j++ )
  168.         {
  169.             if ( W32ServiceTable[i].pServiceCalls[j].fIgnore )
  170.             {
  171.                 DWORD serviceID;
  172.                 
  173.                 serviceID = W32ServiceTable[i].vxdID + j;
  174.                 fwrite( &serviceID, sizeof(serviceID), 1, pFile );
  175.             }
  176.         }
  177.     }
  178.     
  179.     fclose( pFile );
  180.  
  181.     return TRUE;
  182. }
  183.  
  184. BOOL LoadSavedFilterValues(void)
  185. {
  186.     FILE * pFile;
  187.     char szSaveFileName[MAX_PATH];
  188.     DWORD serviceID;
  189.     PWIN32_SERVICE_CALL pWin32ServiceCall;
  190.         
  191.     GetSavedFiltersFilename( szSaveFileName );
  192.     pFile = fopen( szSaveFileName, "rb" );
  193.     if ( !pFile )
  194.     {
  195.         // MessageBox(0, "Unable to open saved filters file!", 0, MB_OK);
  196.         return FALSE;
  197.     }
  198.     
  199.     while ( !feof(pFile) && fread(&serviceID, sizeof(serviceID), 1, pFile) )
  200.     {
  201.         pWin32ServiceCall = LookupWin32ServiceCall( serviceID );
  202.         if ( pWin32ServiceCall )
  203.             pWin32ServiceCall->fIgnore = TRUE;
  204.     }
  205.     
  206.     fclose( pFile );
  207.     
  208.     return TRUE;
  209. }
  210.